package com.matrix.index.ui.home.adapter

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.matrix.basecore.utils.glide.GlideUtil
import com.matrix.index.R
import com.matrix.index.ui.home.bean.SearchBean

class SearchAdapter(data: MutableList<SearchBean>) :
    BaseMultiItemQuickAdapter<SearchBean, BaseViewHolder>(data) {

    init {
        addItemType(SearchBean.JOKE, R.layout.item_text_view)
        addItemType(SearchBean.IMAGE, R.layout.item_image_view)
        addItemType(SearchBean.WALL, R.layout.item_wall_view)
    }

    override fun convert(holder: BaseViewHolder, item: SearchBean) {
        when (item.itemType) {
            SearchBean.JOKE -> {
                holder.setText(R.id.tv_content, item.jokeDesc)
            }

            SearchBean.IMAGE -> {
                GlideUtil.loadImage(
                    item?.imageUrl,
                    context,
                    holder.getView(R.id.iv_cover),
                    R.mipmap.icon_default_bg,
                    false
                )
                holder.setText(R.id.tv_desc, item.imageDesc)
            }

            SearchBean.WALL -> {
                GlideUtil.loadRoundImage(
                    item?.imageUrl,
                    context,
                    holder.getView(R.id.iv_cover),
                    6,
                    R.mipmap.icon_default_bg
                )
                GlideUtil.loadRoundImage(
                    item?.imageUrl,
                    context,
                    holder.getView(R.id.iv_cover_left),
                    6,
                    R.mipmap.icon_default_bg
                )
                GlideUtil.loadRoundImage(
                    item?.imageUrl,
                    context,
                    holder.getView(R.id.iv_cover_right),
                    6,
                    R.mipmap.icon_default_bg
                )

                holder.setText(R.id.tv_desc, item.imageDesc)
            }
        }
    }
}